
package com.carkeeper.search.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//配置类
@Configuration
public class RabbitMQConfig {
    //定义队列名称
    public static final String AD_UPDATE_QUEUE = "ad_update_queue";
    //定义队列名称
    public static final String SEARCH_ADD_QUEUE = "search_add_queue";
    //定义交换机
    public static final String SERVICE_UP_EXCHANGE = "service_up_exchange";
    //定义下架队列名称
    public static final String SEARCH_DEL_QUEUE = "search_del_queue";
    //定义下架交换机
    public static final String SERVICE_DOWN_EXCHANGE = "service_down_exchange";


    @Bean
    public Queue queue() {
        return new Queue(AD_UPDATE_QUEUE);
    }

    @Bean(SEARCH_ADD_QUEUE)
    public Queue queue1() {
        return new Queue(SEARCH_ADD_QUEUE);
    }

    @Bean(SERVICE_UP_EXCHANGE)
    public Exchange exchange() {
        return ExchangeBuilder.fanoutExchange(SERVICE_UP_EXCHANGE).durable(true).build();
    }

    //声明下架交换机
    @Bean(SERVICE_DOWN_EXCHANGE)
    public Exchange exchange1() {
        //使用发布订阅模式fanout
        return ExchangeBuilder.fanoutExchange(SERVICE_DOWN_EXCHANGE).durable(true).build();
    }

    @Bean(SEARCH_DEL_QUEUE)
    public Queue queue3() {
        return new Queue(SEARCH_DEL_QUEUE);
    }

    @Bean
    public Binding bingding(@Qualifier(SEARCH_ADD_QUEUE) Queue queue, @Qualifier(SERVICE_UP_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();

    }

    @Bean
    public Binding bingding1(@Qualifier(SEARCH_DEL_QUEUE) Queue queue, @Qualifier(SERVICE_DOWN_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}

